<template>
	<!-- <view>
		<image class="bg" src="/static/login/log_bg.png" mode="scaleToFill"></image> -->
	<view class="content" :style="{'background':kbackgroundColor}" style="min-height: 100vh">
		<hx-navbar title="我的订单" :back="true" :fixed="false" :color="knavTitleColor" barPlaceholder="hidden"
			transparent="auto"></hx-navbar>
		<view class="order_tab_list">
			<view class="order_tab" :class="{tab_on:current == item.status}"
				:style="current == item.status? [selStyle]:[tabNormaleStyle]" v-for="item,id in tab_list" :key="id"
				@tap="on_tab_click(item)">
				{{item.name}}
			</view>
		</view>
		<view class="container">
			<view class="order_list">
				<view class="order_item" :style="{background:kcellBgColor}" v-for="item,id in list" :key="id">
					<view class="item_info">
						<image :src="item.item.image" mode="aspectFit" class="item_img"></image>
						<view class="item_right">
							<view class="order_status_box">
								<view class="item_name" :style="{'color':knormalColor}">
									{{item.item.name}}
								</view>
								<view style="color: #F1CF99;" v-if="item.status == 0">待支付</view>
								<view style="color: green;" v-if="item.status == 1">已完成</view>
								<view class="color-9" v-if="item.status == 2">已取消</view>
								<!-- 	<view class="see_detail"
									@tap="go_pay(item.goods_id,item.pay_price,item.sn,item.payment_type,item.goods_name,item.image,item.goods_cat,item.goods_code)"
									v-if="item.pay_status == 0">
									去付款
									<n-icon name="right" size="24" color="#ABA9B4"></n-icon>
								</view> -->
							</view>
							<view class="item_code" v-if="item.nft">
								<text class="title" :style="{'color':knormalColor}">商品编号：#{{item.nft.tokenId}}</text>
							</view>
							<view class="item_code" v-if="item.amount">
								<text class="title" :style="{'color':knormalColor}">支付金额：￥{{item.amount|fp}}</text>
							</view>
							<view class="item_code">
								<text class="title" v-if="item.status == 1" :style="{'color':knormalColor}">购入时间：{{item.payTime || ''}}</text>
								<text class="title" v-if="item.status == 2" :style="{'color':knormalColor}">取消时间：{{item.payTime || ''}}</text>
							</view>
							<!-- <view class="item_time cell-item-cb">
								<view class="color-oo item-tui" @click="get_orderRefund(item.sn)"
									v-if="item.refund_status==1">退款</view>
								<view v-else></view>
								<view class="" v-if="item.pay_status != 0">{{item.ctime}}</view>
							</view> -->
							<view class="bottom-view" v-if="item.status == 0">
								<view class="cancel_btn marginL" :style="{background:kbuttonBgColor}" @tap="go_pay(item)" >立即支付</view>
								<view class="cancel_btn" :style="{background:kbuttonBgColor}" @tap="cancel(item)" >取消订单</view>
							</view>
						</view>
					</view>
				</view>
				<view class="none_box" v-if="list.length == 0">
					<image src="@/static/without.png" mode="widthFix"></image>
				</view>
			  <uni-popup ref="tipsPopup" type="center" :maskBackgroundColor="'rgba(0,0,0,0.5)'" :isMaskClick="false">
					<view class="store-view store-border-all tips-padding"
						:style="{'background':kbackgroundColor,color:knormalColor}"
						:class="[{'alert-border-black alert-border-shadow-black':ktheme =='black'},{'alert-border-purple':ktheme =='purple'}]">
						<text class="popup-title">提醒</text>
						<text class="popup-subtitle">批量订单无法操作，请前往批量订单界面</text>
						<view class="tips-bottom">
							<view class="tips-button"
								:class="[{'tips-cancel-bg-black':ktheme =='black'},{'tips-cancel-bg-white':ktheme =='purple'}]"
								@click="closetipsPopup()">取消</view>
							<view class="tips-button" style="color: black;" :style="{background:kbuttonBgColor}" @click="opentipsPopup()">确认
							</view>
						</view>
					</view>
				</uni-popup>
			
			
				<!-- 提醒 批量取消-->
				<uni-popup ref="tiCancel" type="center" :maskBackgroundColor="'rgba(0,0,0,0.5)'" :isMaskClick="false">
					<view class="store-view store-border-all tips-padding"
						:style="{'background':kbackgroundColor,color:knormalColor}"
						:class="[{'alert-border-black alert-border-shadow-black':ktheme =='black'},{'alert-border-purple':ktheme =='purple'}]">
						<text class="popup-title">提醒</text>
						<text class="popup-subtitle">确定取消订单吗？</text>
						<view class="tips-bottom">
							<view class="tips-button"
								:class="[{'tips-cancel-bg-black':ktheme =='black'},{'tips-cancel-bg-white':ktheme =='purple'}]"
								@click="closetiCancel()">取消</view>
							<view class="tips-button" style="color: black;" :style="{background:kbuttonBgColor}" @click="opentiCancel()">确认
							</view>
						</view>
					</view>
				</uni-popup>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		filters: {
			filterTime(val) {
				return uni.$u.timeFormat(parseInt(val), 'yyyy-mm-dd hh:MM:ss')
			}
		},
		data() {
			return {
				tab_list: [{
						name: '全部',
						status: '',
					},
					{
						name: '待支付',
						status: '0',
					},
					{
						name: '已完成',
						status: '1',
					},
					{
						name: '已取消',
						status: '2',
					},
				],
				current: '',
				page: 1,
				limit: 10,
				list: [],
				hasNextPage: true,
				orderId:""
			}
		},
		onLoad(options) {
			this.$nextTick(() => {
				if (options.status) this.current = parseInt(options.status);
				this.get_data_list()
			});
		},
		onShow() {
			if (this.current) {
				this.get_data_list()
			}
		},
		onReachBottom() {
			if (this.hasNextPage) {
				let new_page = this.page + 1
				let data = {
					pageNo: new_page,
					// limit: this.limit,
					status: this.current
				}
				this.$api.getOrderList(data, res => {
					if (res.status) {
						this.list = this.list.concat(res.data);
						this.hasNextPage = res.data.length >= this.limit;
						this.page = new_page
					}
				})
			}
		},
		onPullDownRefresh() {
			this.list = [],
				this.page = 1;
			this.hasNextPage = true;
			let data = {
				pageNo: this.page,
				status: this.current
			}
			this.$api.getOrderList(data, res => {
				if (res.status) {
					this.list = this.list.concat(res.data);
					this.hasNextPage = res.data.length >= this.limit;
				}
				uni.stopPullDownRefresh()
			})
		},
		methods: {
			get_orderRefund(sn) {
				this.$api.orderRefund({
					sn: sn
				}, res => {
					if (res.status) {
						this.get_data_list()
						this.$common.errorToShow(res.msg)
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
			get_data_list: function() {
				this.page = 1;
				this.hasNextPage = true;
				this.list = []
				let data = {
					status: this.current,
					pageNo: this.page,
					// limit: this.limit
				}
				this.$api.getOrderList(data, res => {
					if (res.status) {
						this.list = res.data;
						this.hasNextPage = res.data.length >= this.limit
					}
				})
			},
			on_tab_click: function(item) {
				this.current = item.status;
				this.get_data_list()
			},
			go_pay: function(item) {
				let source = 1
				// #ifdef APP
				source = 5
				// #endif
				// #ifdef H5
				source = 2
				// #endif
				// #ifdef MP
				source = 3
				// #endif
				// let data = {
				// 	goods_id: id,
				// 	source: source
				// }
				// this.$api.createOrder2(data, res => {
				// 	if (res.status) {
				// 		let pay_data = res.data;
				if (item.batchId == null) {
					let ordersString = encodeURIComponent(JSON.stringify(item.unlockLukeList));
					this.$common.redirectTo('/pages/payment/index?order_id=' + item.orderId + '&type=' + item.type +'&cid=' + item.item.cid + '&unlockLukeList=' + ordersString+'&payWay='+item.payWay)
				} else {
					this.$refs.tipsPopup.open()
				}


				// this.$common.redirectTo('/pages/payment/batch?order_id=' + item.orderId+'&type='+item.type)
				// } else {
				// 	this.$common.errorToShow(res.msg)
				// }
				// })

			},
			opentipsPopup() {
				this.$refs.tipsPopup.close()
				uni.redirectTo({
					url: '/pages/user/order/orderbatch'
				})
			},
			closetipsPopup() {
				this.$refs.tipsPopup.close()
			},
			
			opentiCancel(){
				let data = {
					orderId:this.orderId
				}
				this.$api.cancelOrder(data, res => {
					if (res.status) {
						this.$common.successToShow('取消成功')
						this.get_data_list()
					} else {
						this.$common.errorToShow(res.message)
					}
				this.$refs.tiCancel.close()
				})
				
				},
			closetiCancel(){
				this.$refs.tiCancel.close()
			},
			cancel: function(item) {
				this.orderId=item.orderId
				 if (item.batchId == null) {
					 	this.$refs.tiCancel.open()
				 }else{
				this.$refs.tipsPopup.open()
				 }
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tab_bg2 {
		width: 100%;
		position: absolute;
		bottom: 0;
		height: 283rpx;
		z-index: 0;
	}

	.container {
		// padding: 0 20rpx;
	}

    .bottom-view{
		margin-top: 20rpx;
		display: flex;
		flex-direction: row-reverse;
		align-items: center;
		.cancel_btn {
			width: 140rpx;
			height: 44rpx;
			border-radius: 100rpx;
			text-align: center;
			line-height: 44rpx;
			font-size: 20rpx;
			color: black;
			float: right;
		}
		.marginL {
			margin-left: 20rpx;
		}
	}
	.order_item {
		width: 100%;
		background-color: $bg-box;
		border-radius: 20rpx;
		padding: 20rpx 0;
		margin-bottom: 20rpx;

		.item_info {
			padding: 20rpx;
			display: flex;
			align-items: center;

			.item_img {
				width: 140rpx;
				height: 140rpx;
				margin-right: 30rpx;
			}

			.item_right {
				flex: 1;
				display: flex;
				flex-direction: column;
				padding-right: 10rpx;
				.order_status_box {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 24rpx;
					color: #333;
					.item_name {
						width: 75%;
						display: flex;
						align-items: center;
						// justify-content: space-between;
						line-height: 40rpx;
						font-size: 28rpx;
						color: #141519;
						overflow: hidden;
						text-overflow: ellipsis;
					}
				}
				.item_code {
					font-size: 22rpx;
					margin-top: 8rpx;
					display: flex;
					flex-direction: row;
					align-items: center;
                    opacity: 0.6;
					.title {
						color: #141519;
					}

					.subtitle {
						color: #FE005A;
					}
				}

				.item_time {
					padding-top: 10rpx;
					font-size: 20rpx;
					color: #999;
					text-align: right;

					.item-tui {
						border: solid 1rpx #FE005A;
						color: #FE005A !important;
						padding: 5rpx 15rpx;
						border-radius: 20rpx;
					}
				}
			}
		}
	}
	.none_box {
		width: 534rpx;
		margin: 117rpx auto;
		font-size: 32rpx;
		color: #ABA9B4;
	}
	.none_box image {
		width: 100%;
		height: 534rpx;
		margin-bottom: 10rpx;
	}

	.order_tab_list {
		position: relative;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 55rpx 10rpx 55rpx;
		.order_tab {
			width: 119rpx;
			// height: 54rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			z-index: 2;
			font-size: 28rpx;
			color: var(--tabNormalColor);
		}
		.tab_on {
			color: var(--selectColorSize);
		}
		.tab_on::after {
			display: block;
			clear: both;
			content: '';
			width: 65%;
			height: 4rpx;
			// background:red;
			background: var(--selBcakborder);
			border-radius: 100rpx;
			position: absolute;
			left: 50%;
			bottom: -12rpx;
			transform: translateX(-50%);
		}
	}
	.order_list {
		width: 100%;
		position: relative;
		padding: 30rpx 40rpx;
	}

	.store-view {
		display: flex;
		flex-direction: column;
		margin-bottom: -6rpx;
		max-height: 1000rpx;

		.tips-bottom {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
			font-size: 28rpx;
			margin: 0 40rpx 40rpx 40rpx;

			.tips-button {
				padding: 20rpx 0;
				width: 240rpx;
				text-align: center;
				border-radius: 40rpx;
				color: white;
			}

			.tips-cancel-bg-black {
				border: 2rpx #F6D9A9 solid;
				background: #333333;
				color: white;
			}

			.tips-cancel-bg-white {
				border: 2rpx #999999 solid;
				background: white;
				color: #333333;
			}
		}

		.freeze-row-black {
			background: rgba(255, 0, 0, 0.5);
		}

		.freeze-row-white {
			background: rgba(255, 0, 0, 0.1);
		}

		.freeze-row {
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 14rpx 40rpx;
			width: 100%;

			.freeze-icon {
				width: 34rpx;
				height: 28rpx;
			}

			.freeze-text {
				color: #EA4729;
				margin-left: 20rpx;
			}
		}

		.popup-title {
			width: 100%;
			margin-top: 40rpx;
			text-align: center;
		}

		.popup-subtitle {
			font-size: 28rpx;
			padding: 40rpx;
		}

		.popup-disabel-title {
			color: #F65656;
			font-size: 28rpx;
			padding: 40rpx;
		}

		.store-item {
			padding: 20rpx 40rpx;
			display: flex;
			flex-direction: row;
			align-items: center;

			.store-image {
				width: 100rpx;
				height: 100rpx;
			}

			.store-column {
				display: flex;
				flex-direction: column;
				margin: 0 20rpx;
				position: relative;
				width: 50%;

				.store-title {
					font-size: 30rpx;
				}

				.store-small-title {
					font-size: 26rpx;
				}

				.store-tag {
					padding: 4rpx 18rpx;
					font-size: 24rpx;
					margin-top: 6rpx;
					margin-right: auto;
				}

				.store-number {
					margin-top: 4rpx;
					font-size: 24rpx;
				}
			}

			.award-success-icon {
				width: 200rpx;
				height: 160rpx;
			}

			.store-buy {
				margin-left: auto;
				padding: 8rpx 30rpx;
				border-radius: 46rpx;
				font-size: 26rpx;
				color: white;
			}

			.store-buy-black {
				border-radius: 8rpx;
				border: 2rpx #58CC7B solid;
				background-color: rgba(88, 204, 123, 0.20);
				color: #58CC7B;
			}

			.store-buy-white {
				border-radius: 8rpx;
				border: 2rpx #999999 solid;
				background-color: white;
				color: #333333;
			}
		}
	}
</style>